<#include "admin/common/include/html_head.html"> <#include
"admin/common/include/sysparam.html"> <#include
"admin/common/include/pagination.html">
<div class="row-fluid">
	<div class="span12">
		<!-- BEGIN EXAMPLE TABLE PORTLET-->
		<div class="portlet box">
			<div class="portlet-title">
				<div class="caption">
					<h5>商品管理</h5>
				</div>
			</div>
			<div class="portlet-body form">
				<form id="resSearchForm">
					<div class="row-fluid">
						<div class="span6">
							<div class="dataTables_filter" id="sample_1_filter">
								<label>名称: <input type="text" aria-controls="sample_1"
									value="${_QUERY_s_like_name}" class=" m-wrap medium"
									name="_QUERY_s_like_name" id="_QUERY_s_eq_name"></label>
							</div>
						</div>
						<div class="span6">
							<div class="dataTables_filter" id="sample_1_filter">
								<label>是否上架: <@select paramCode=resOnlineType
									value=(_QUERY_n_eq_is_online)?if_exists item='
									name="_QUERY_n_eq_is_online"'/></label>
							</div>
						</div>
					</div>
					<div class="row-fluid">
						<div class="span6">
							<div class="dataTables_filter" id="sample_1_filter">
								<label>显示: <@select paramCode=resHotType
									value=(_QUERY_n_eq_is_hot)?if_exists item='
									name="_QUERY_n_eq_is_hot"'/></label>
							</div>
						</div>
						<div class="span6">
							<div class="dataTables_filter" id="sample_1_filter">
								<label>分类: <input type="hidden" name="_QUERY_n_eq_category_id"
									id="_QUERY_n_eq_category_id" value="${(_QUERY_n_eq_category_id)?if_exists}"
									  /> <input
									class="m-wrap small " name="categoryName" id="categoryName"
									readonly="readonly"
									value="${(categoryName)?if_exists}" type="text" />
									<button type="button" id="chooseCategoryBtn" class="btn blue">选择分类</button></label>
							</div>
						</div>
					</div>
				</form>

				<div class="alert alert-error " id="errTip" style="display: none;"></div>
				<div class="alert alert-success " id="sucTip" style="display: none;"></div>
				<div class="tab-pane active" id="tab_1">
					<div class="portlet-body">
						<div class="clearfix">
							<button id="res_query_btn" class="btn blue">
								<i class="icon-search"></i>&nbsp;&nbsp;查询
							</button>
							<button id="res_add_btn" class="btn blue">
								<i class="icon-plus"></i>&nbsp;&nbsp;新增
							</button>
							<button id="res_del_btn" class="btn blue">
								<i class="icon-trash"></i>&nbsp;&nbsp;删除
							</button> 
						</div>
						<br>
						<form action="${_contextPath}/Admin-Res-show.action"
							id="QueryForm">
							<table class="table table-striped table-bordered table-hover  table-advance  " id="resTable">
								<thead>
									<tr>
										<th style="width: 8px;"><input type="checkbox"
											class="group-checkable" data-set="#resTable .checkboxes" /></th>

										<th>名称</th>
										<th>图片</th> 
										<th>价格</th>
										<th>库存</th>
										<th>显示</th>
										<th>上下架</th>
										<th>更新时间</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<#list pageBean.result as resource >
									<tr>
										<td><input type="checkbox" class="checkboxes"
											value="${resource.id}" /></td>  
										<td>${resource.name}</td>
										<td><img
											src="${contextPath}${(resource.imageUrl)?if_exists}"
											width="80" height="80" /></td>
								    	 
										<td>${resource.price}</td>
										<td>${resource.stockNum}</td>
										<td><@translate paramCode=resHotType
											value=(resource.isHot)?if_exists /></td>
										<td><@translate paramCode=resOnlineType
											value=(resource.isOnline)?if_exists /></td>
										<td>${resource.lastUpdate}</td>
										<td><a href='#' name="edit_action" value="${resource.id}">编辑商品</a><br>
										<a href='#' name="offline_action" value="${resource.id}">下架商品</a><br>
										<a href='#' name="delete_action" value="${resource.id}">删除商品</a></td>
									<tr></#list>
								</tbody>
							</table>
						</form>
						<@pagination searchFormId='resSearchForm' pBean=pageBean />
					</div>
				</div>

			</div>
			<!-- END EXAMPLE TABLE PORTLET-->
		</div>
	</div>
</div>

<script>
	jQuery(document).ready(function() {
		App.init();
		var queryUrl = '${contextPath}/Admin-Res-show.action';
		tableAction.init({
			tableId : 'resTable',
			queryUrl : queryUrl,
			deleteUrl : '${contextPath}/Admin-Res-delete.action',
			editUrl : '${contextPath}/Admin-Res-showEditForm.action',
			queryBtnId : 'res_query_btn',
			deleteBtnId : 'res_del_btn',
			searchFormId : 'resSearchForm',
			isPopEditForm : false,
			editBtnId : 'res_add_btn'
		});
		$('#res_reset_btn').bind("click", function() { 
			 document.getElementById("resSearchForm").reset();
		});
		$("#chooseCategoryBtn").bind("click", function() {
			var url = '${contextPath}/Admin-ResCategory-selectCategory.action?categoryId=_QUERY_n_eq_category_id&categoryName=categoryName';
			common.popHtml(url, 'navModel');
		});
		
		$("a[name='offline_action']").bind('click', function() {
			var resourceId = $(this).attr('value');
			var _errZoneId=  'errtip';
			var offlineUrl = '${contextPath}/Admin-Res-offline.action?resourceId='+resourceId;
			common.alert({
				content : '是否下架选中项？',
				showAction : true,
				actionContent : '确定',
				actionFn : function() { 
					ajax.syncJsonRequest({
						url : offlineUrl,
						success : function(data) {
							if (!data || !data.success) {
								$('#'+_errZoneId).html(data.retinfo);
								$('#'+_errZoneId).show();
							}
							if (data.success) {
								common.alert({
									content : data.retinfo,
									closeFn : function() {
										 mainFrame.addContainer(queryUrl); 
									}
								});
							}
						}
					});
				}
			});
		});
		
		$("a[name='delete_action']").bind('click', function() {
			var resourceId = $(this).attr('value');
			var _errZoneId=  'errtip';
			var offlineUrl = '${contextPath}/Admin-Res-delete.action?resourceId='+resourceId;
			common.alert({
				content : '是否删除选中项？',
				showAction : true,
				actionContent : '确定',
				actionFn : function() { 
					ajax.syncJsonRequest({
						url : offlineUrl,
						success : function(data) {
							if (!data || !data.success) {
								$('#'+_errZoneId).html(data.retinfo);
								$('#'+_errZoneId).show();
							}
							if (data.success) {
								common.alert({
									content : data.retinfo,
									closeFn : function() {
										 mainFrame.addContainer(queryUrl); 
									}
								});
							}
						}
					});
				}
			});
		});
	});
</script>
